package com.base.api.qq;

import com.alibaba.druid.util.StringUtils;
import com.base.api.qq.callback.MessageCallback;
import com.base.api.qq.client.SmartQQClient;
import com.base.api.qq.model.DiscussMessage;
import com.base.api.qq.model.GroupMessage;
import com.base.api.qq.model.Message;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author ScienJus
 * @date 2015/12/18.
 */
public class Application {

    public static void main(String[] args) {
        //创建一个新对象时需要扫描二维码登录，并且传一个处理接收到消息的回调，如果你不需要接收消息，可以传null
        SmartQQClient client = new SmartQQClient(new MessageCallback() {

            @Override
            public void onMessage(Message message, SmartQQClient client) {
                System.out.println(message.getUserId());
                client.sendMessageToFriend(message.getUserId(), "收到：" + message.getContent());
            }

            @Override
            public void onGroupMessage(GroupMessage message, SmartQQClient client) {
                System.out.println(message.getContent());
            }

            @Override
            public void onDiscussMessage(DiscussMessage message, SmartQQClient client) {
                System.out.println(message.getContent());
            }
        });
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            if(StringUtils.equals("close", scanner.next())){
                System.out.println("Close...");
                break;
            }
        }
        //使用后调用close方法关闭，你也可以使用try-with-resource创建该对象并自动关闭
        try {
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
